package com.翻转数字;

public class Solution {
	
	public int reverse(int x) {
		if (x == 0)
			return 0;
		boolean isneg = false;
		// 判断正负
		if (x < 0) {
			isneg = true;
			x = x * -1;
		}
		long res = 0;
		while (x > 0) {
			res = res * 10 + x % 10;
			if (res > Integer.MAX_VALUE)
				return 0;
			x = x / 10;
		}
		if (isneg) {
			res = res * -1;
		}
		return (int) res;

	}

}
